<?php
class newsAction extends Action {
	public function index() {
		echo 'Welcome to News/Index!';
	}
	public function show() {
		$title = '消息显示';
		$this->assign('title', $title);
		
		$db = new Model('news');
		
		$data['title'] = '北京';
		$data['content'] = '中国人民';
		$data['create_time'] = time();
		//$db->add($data);
		print_r($db->find(1));
		$a = 12345678901234;
		echo '<hr>'.$a.'<hr>';
		
		$this->display();
	}
	
	public function get_new() {
		$db = new Model('news');
	}
	
	public function get_str() {
		set_time_limit(0);
		//配置
		$_run_time_start = microtime(1);
		$_time_max_limit = 300;	//循环时间限制
		$_time_min_limit = 0;
		$_loop_limit = 10000;	//循环次数限制
		$_time_step = 100*1000;	//每次循环等待时间
		
		$str_return = '';
		$file = 'E:\www\ams\trunk\pro\htdocs\sql.htm';
		//循环检查，不超时不超次数
		$i = 0;
		$stop = false;
		while(microtime(1)-$_run_time_start < $_time_max_limit && $i < $_loop_limit && $stop == false) {
			clearstatcache();
			$mtime = filemtime($file);
			
			if($_SESSION['mtime'] == $mtime) {
				//等待后继续循环
				usleep($_time_step);
				$i++;
			} else {
				$_SESSION['mtime'] = $mtime;
				$stop = true;
			
				$content = file_get_contents($file);
				preg_match('/Processed in(.*)queries/', $content, $arr);
				$str_return = $i.' - '.$arr[0].' <b>'.date('Y-m-d H:i:s').'</b> '.date('Y-m-d H:i:s', $_SESSION['mtime']);
			}
		}
		//时间未到则等待
		$t = 0;
		if(microtime(1)-$_run_time_start < $_time_min_limit) {
			$t = ($_time_min_limit-(microtime(1)-$_run_time_start))*1000000;
			usleep($t);
		} elseif (microtime(1)-$_run_time_start >= $_time_max_limit) {
			$str_return = '超时';
		}
		//touch('E:\www\ams\trunk\pro\htdocs\sql.htm');
		echo $str_return.' - '.round(microtime(1)-$_run_time_start, 3);
	}
	
	public function de_data() {
		$db_doubleclick = $this->de_connect();
		$sql = "SELECT 
				to_char(startdate, 'yyyy-mm-dd [D]') day,sum(impressions) imp,sum(clicks),sum(clicks)/sum(impressions) 
				
				FROM 
				admanager70.ng_sum_fixed_c
				
				WHERE 
				startdate>to_date('2010-04-20','yyyy-mm-dd')
				
				GROUP BY
				admanager70.ng_sum_fixed_c.startdate";
		$res = $db_doubleclick->query($sql);
		$res->setFetchMode(PDO::FETCH_ASSOC);
		$rs = $res->fetchAll();
	}
	
	public function test_flush() {
		ob_end_flush();
		for($i=1; $i<10; $i++) {
			echo time().'<br>';	
			usleep(100000);
			flush();
		}
	}
}
?>
